﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using EnvDTE80;
using EnvDTE;

namespace BovespaMaintainabilityRules
{
    public sealed class Rule_ClassNameMustMatchFile : BaseAddIn.Rules.BaseRuleAddIn
    {
        public Rule_ClassNameMustMatchFile()
            : base("BovespaClassNameMustMatchFile",
                   "BovespaMaintainabilityRules.BovespaMaintainabilityRules",
                   typeof(Rule_FileMustHaveOnlyOnePublicType).Assembly)
        {
        }

        protected sealed override void Check(CodeClass2 classe)
        {
            string fileName = Path.GetFileNameWithoutExtension(classe.StartPoint.Parent.Parent.FullName);

            if (!fileName.Contains(".Designer.")
                && classe.Parent is CodeNamespace
                && fileName.Split('.').Length <= 1
                && classe.Name != fileName)
            {
                GeraProblemaAddIn(classe.StartPoint.Parent.Parent.FullName,
                                 classe.StartPoint.Line,
                                 classe.StartPoint.DisplayColumn,
                                 "ClassNameMustMatchFileResolution",
                                 classe.Name);
            }
        }
    }
}
